package com.jyw.flowable.controller;

import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.flowable.domain.WfCategory;
import com.jyw.flowable.service.IWfCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程分类Controller
 *
 * @author zhangcheng
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/flowable/category")
public class WfCategoryController extends BaseController {
    @Resource
    private IWfCategoryService wfCategoryService;

    /**
     * 查询流程分类列表
     */
    @PreAuthorize("@ss.hasPermi('flowable:category:list')")
    @GetMapping("/list")
    public TableDataInfo<WfCategory> list(WfCategory wfCategory) {
        startPage();
        List<WfCategory> list = wfCategoryService.selectWfCategoryList(wfCategory);
        return getDataTable(list);
    }

    /**
     * 查询所有流程分类
     *
     * @return
     */
    @GetMapping("/getList")
    public CommonResult<List<WfCategory>> getList(){
        List<WfCategory> list=wfCategoryService.list();
        return CommonResult.success(list);
    }

    /**
     * 获取流程分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('flowable:category:query')")
    @GetMapping(value = "/{id}")
    public CommonResult<WfCategory> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(wfCategoryService.selectWfCategoryById(id));
    }

    /**
     * 新增流程分类
     */
    @PreAuthorize("@ss.hasPermi('flowable:category:add')")
    @Log(title = "流程分类", businessType = BusinessType.INSERT)
    @PostMapping(value = "add")
    public CommonResult add(@RequestBody WfCategory wfCategory) {
        return CommonResult.success(wfCategoryService.insertWfCategory(wfCategory));
    }

    /**
     * 修改流程分类
     */
    @PreAuthorize("@ss.hasPermi('flowable:category:edit')")
    @Log(title = "流程分类", businessType = BusinessType.UPDATE)
    @PutMapping(value = "edit")
    public CommonResult edit(@RequestBody WfCategory wfCategory) {
        return CommonResult.success(wfCategoryService.updateWfCategory(wfCategory));
    }

    /**
     * 删除流程分类
     */
    @PreAuthorize("@ss.hasPermi('flowable:category:remove')")
    @Log(title = "流程分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(wfCategoryService.deleteWfCategoryByIds(ids));
    }
}
